#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstdint>

using namespace std;

class Solution {
public:
    int firstUniqChar(string s) {
      const static int LEN = 26;
      int table[LEN] = {0};
      int index[LEN] = {0};
      int min = 0xFFFF;
      int flag = 0;
      for (int i = 0; i < s.length(); i++){
        table[s[i] - 'a']++;
        index[s[i] - 'a'] = i;
      }
      for (int i = 0; i < LEN; i++){
        if (1 == table[i]){
          if (index[i] < min){
            min = index[i];
            flag = 1;
          }
        }
      }
      if (flag){
        return min;
      }
      return -1;
    }
};

int main(void)
{
    string s = "testztesttestaabbcxxxtetad";
    Solution su;
    int index = su.firstUniqChar(s);
    printf("index is %d, value is %c\r\n", index, s[index]);
    return 0;
}
